package org.springblade.modules.repair.enums;


import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springblade.modules.repair.vo.TaskStatusVO;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Description 任务状态枚举
 * @Author ysq
 * @Date 2022/3/11
 **/
@Getter
@AllArgsConstructor
public enum TaskStatusEnum {

	/**
	 * 保养任务状态
	 */
	BY_DISABLE(1, MaintainPlanContentEnum.MAINTAIN_BY.getId(), "待开始"),
	BY_PROCESSED(2, MaintainPlanContentEnum.MAINTAIN_BY.getId(),"进行中"),
	BY_FINISH(3, MaintainPlanContentEnum.MAINTAIN_BY.getId(), "提交任务"),
	BY_MAINTAIN_SIGN(5, MaintainPlanContentEnum.MAINTAIN_BY.getId(), "维保签字"),
	BY_SIGN(4, MaintainPlanContentEnum.MAINTAIN_BY.getId(), "已完成"),

	/**
	 * 维修任务状态
	 */
	WX_ALLOCATION(0, MaintainPlanContentEnum.MAINTAIN_WX.getId(), "待分配"),
	WX_PENDING(1, MaintainPlanContentEnum.MAINTAIN_WX.getId(), "待处理"),
	WX_TO_START(2, MaintainPlanContentEnum.MAINTAIN_WX.getId(),"待开始"),
	WX_UNDER_WAY(3, MaintainPlanContentEnum.MAINTAIN_WX.getId(), "维修中"),
	WX_SIGN_FINISH(4, MaintainPlanContentEnum.MAINTAIN_WX.getId(), "已完成"),

	//审核不通过--之前已关闭文案调整为已撤回
	WX_CLOSED(5, MaintainPlanContentEnum.MAINTAIN_WX.getId(), "已撤回"),
	WX_TURN_DOWN(6, MaintainPlanContentEnum.MAINTAIN_WX.getId(), "已驳回"),
	//审核通过以后再关闭工单---工单状态变更为已关闭
	WX_CHECK_PASS_CLOSED(7, MaintainPlanContentEnum.MAINTAIN_WX.getId(), "已关闭"),

	/**
	 * 救援任务状态
	 */
	JY_DISPATCH(1, MaintainPlanContentEnum.MAINTAIN_KR.getId(), "调度中"),
	JY_TO_START(2, MaintainPlanContentEnum.MAINTAIN_KR.getId(),"待开始"),
	JY_PROCESSED(3, MaintainPlanContentEnum.MAINTAIN_KR.getId(), "已出发"),
	JY_ARRIVE(4, MaintainPlanContentEnum.MAINTAIN_KR.getId(), "已到达"),
	JY_RESCUE(5, MaintainPlanContentEnum.MAINTAIN_KR.getId(), "已救援"),
	JY_CANCEL(6, MaintainPlanContentEnum.MAINTAIN_KR.getId(), "已撤回"),

	/**
	 * 选择部件任务状态
	 */
	PARTS_APPLY(0, MaintainPlanContentEnum.MAINTAIN_PARTS.getId(), "需求审批"),
	PARTS_APPROVE(1, MaintainPlanContentEnum.MAINTAIN_PARTS.getId(), "信息审核"),
	PARTS_OFFER(2, MaintainPlanContentEnum.MAINTAIN_PARTS.getId(), "销售生单"),
	PARTS_REPLY(10, MaintainPlanContentEnum.MAINTAIN_PARTS.getId(), "销售生单"),
	PARTS_PROCUREMENT(11, MaintainPlanContentEnum.MAINTAIN_PARTS.getId(), "待发货"),
	PARTS_SHIPMENTS(3, MaintainPlanContentEnum.MAINTAIN_PARTS.getId(), "待发货"),
	PARTS_RECEIVE(12, MaintainPlanContentEnum.MAINTAIN_PARTS.getId(), "待签收"),
	PARTS_ALLOCATION(4, MaintainPlanContentEnum.MAINTAIN_PARTS.getId(), "待分配"),
	PARTS_TO_START(5, MaintainPlanContentEnum.MAINTAIN_PARTS.getId(), "待更换"),
	PARTS_CHANGE(6, MaintainPlanContentEnum.MAINTAIN_PARTS.getId(), "更换中"),
	PARTS_FINISH(7, MaintainPlanContentEnum.MAINTAIN_PARTS.getId(), "已完成"),
	PARTS_CLOSE(8, MaintainPlanContentEnum.MAINTAIN_PARTS.getId(), "已关闭"),
	PARTS_WITHDRAW(9, MaintainPlanContentEnum.MAINTAIN_PARTS.getId(), "已撤回"),


	/**
	 * 事务任务状态
	 */
	SW_ALLOCATION(1, MaintainPlanContentEnum.MAINTAIN_AFFAIR.getId(), "待分配"),
	SW_TO_START(2, MaintainPlanContentEnum.MAINTAIN_AFFAIR.getId(), "待开始"),
	SW_UNDER_WAY(3, MaintainPlanContentEnum.MAINTAIN_AFFAIR.getId(), "进行中"),
	SW_SIGN_FINISH(4, MaintainPlanContentEnum.MAINTAIN_AFFAIR.getId(), "已完成"),
	SW_CLOSED(5, MaintainPlanContentEnum.MAINTAIN_AFFAIR.getId(), "已关闭"),


	/**
	 * 质检任务状态
	 */
	ZJ_ALLOCATION(1, MaintainPlanContentEnum.MAINTAIN_CHECK.getId(), "待分配"),
	ZJ_TO_START(2, MaintainPlanContentEnum.MAINTAIN_CHECK.getId(), "待开始"),
	ZJ_UNDER_WAY(3, MaintainPlanContentEnum.MAINTAIN_CHECK.getId(), "进行中"),
	ZJ_SIGN_FINISH(4, MaintainPlanContentEnum.MAINTAIN_CHECK.getId(), "已完成"),
	ZJ_CLOSED(5, MaintainPlanContentEnum.MAINTAIN_CHECK.getId(), "已关闭"),

	/**
	 * 整改任务状态
	 */
	ZG_ALLOCATION(1, MaintainPlanContentEnum.ABARBEITUNG.getId(), "待分配"),
	ZG_TO_START(2, MaintainPlanContentEnum.ABARBEITUNG.getId(), "待开始"),
	ZG_UNDER_WAY(3, MaintainPlanContentEnum.ABARBEITUNG.getId(), "进行中"),
	ZG_SIGN_FINISH(4, MaintainPlanContentEnum.ABARBEITUNG.getId(), "已完成"),
	ZG_CLOSED(5, MaintainPlanContentEnum.ABARBEITUNG.getId(), "已关闭");

	/**
     * 任务状态
	 */
	int status;

	/**
     * 任务类型
	 */
	int typeStatus;

	/**
     * 状态名称
	 */
	String name;

	/**
	 * 获取状态名称
	 * @param typeStatus 任务类型
	 * @param status 任务状态
	 * @return
	 */
	public static String getTaskName(Integer typeStatus, Integer status) {
		TaskStatusEnum[] taskStatuses = TaskStatusEnum.values();
		for (TaskStatusEnum task : taskStatuses) {
			if (task.getTypeStatus() == typeStatus && task.getStatus() == status) {
				return task.getName();
			}
		}
		return null;
	}

	/**
	 * 根据类型获取任务状态集合
	 * @param typeStatus
	 * @return
	 */
	public static List<TaskStatusVO> getTaskStatusByType(Integer typeStatus) {
		List<TaskStatusVO> list = new ArrayList<>();
		TaskStatusEnum[] taskStatuses = TaskStatusEnum.values();
		for (TaskStatusEnum task : taskStatuses) {
			if (task.getTypeStatus() == typeStatus) {
				TaskStatusVO taskStatus = new TaskStatusVO();
				taskStatus.setStatus(task.getStatus());
				taskStatus.setName(task.getName());
				list.add(taskStatus);
			}
		}
		return list;
	}

	/**
	 * 获取部件更换工单状态对应审批描述
	 * @param status
	 * @return
	 */
	public static String getPartsAuditStatusName(Integer status){
		if(PARTS_ALLOCATION.getStatus() <= status && status <= PARTS_FINISH.getStatus()){
			return "审批通过";
		}else if(status.equals(PARTS_CLOSE.getStatus())){
			return "审批不通过";
		}else if(status.equals(PARTS_WITHDRAW.getStatus())){
			return "已撤回";
		}else {
			return "审批中";
		}
	}

}
